export class Logger {
  log: Function;
  warn: Function;
  error: Function;
  info: Function;

  /**
   * @desc 产生一个新服务
   * @param enableTracing 是否启用调用栈模式
   */
  static forRoot(enableTracing: boolean = false): Logger {
    return new Logger(enableTracing);
  }

  constructor(enableTracing: boolean = false) {
    if (enableTracing) {
      this.generateTracingType();
    } else {
      this.generateType();
    }
  }

  /**
   * @desc 调用栈日志类型等级工厂函数
   * @param type 日志等级类型
   */
  private typeTracingFac(type): Function {
    return window.console[type];
  }

  /**
   * @desc 混淆日志类型等级工厂函数
   * @param type 日志等级
   */
  private typeFac(type): Function {
    return function () {
      window.console[type](arguments);
    };
  }

  /**
   * @desc 产生调用栈所有日志等级函数
   */
  private generateTracingType(): void {
    this.log = this.typeTracingFac('log');
    this.warn = this.typeTracingFac('warn');
    this.error = this.typeTracingFac('error');
    this.info = this.typeTracingFac('info');
  }

  /**
   * @desc 产生混淆所有日志等级函数
   */
  private generateType(): void {
    this.log = this.typeFac('log');
    this.warn = this.typeFac('warn');
    this.error = this.typeFac('error');
    this.info = this.typeFac('info');
  }

}
